using System.Collections.Generic;
using UnityEngine;

public class FriendPool : MonoBehaviour
{
	public static FriendPool instance;

	public List<Fri_AIController> friendlist;

	public Transform planeparent;

	public Transform shipparent;

	public Transform buildingparent;

	private GameObject tempobj;

	private Fri_plane tempplane;

	private Fri_ship tempship;

	private Fri_building tempbuild;

	private int frilist_index;

	private int minimap_plane_index;

	private int minimap_ship_index;

	private int minimap_build_index;

	public bool ishaveboss;

	private GameObject bossobj;

	public int FriPlane_num;

	public int FriShip_num;

	public int FriBuild_num;

	private int[] LowQuality_limitnum = new int[3]
	{
		2,
		3,
		3
	};

	public GameObject[] planeres_objs;

	private string infostr;

	private Vector3 dirtemp;

	private List<int> rightval = new List<int>();

	private int indextemp;

	private int valueright;

	private int backindex;

	private int buildnum;

	private void Awake()
	{
		if (instance == null)
		{
			instance = this;
		}
		FriPlane_num = 0;
		FriShip_num = 0;
		FriBuild_num = 0;
	}

	public void DisableAllFri()
	{
		for (int i = 0; i < friendlist.Count; i++)
		{
			UnityVersionUtil.SetActiveRecursive(friendlist[i].gameObject, state: false);
			friendlist[i].isdie = true;
		}
		ishaveboss = false;
	}

	public void EnableAllFri()
	{
		for (int i = 0; i < friendlist.Count; i++)
		{
			UnityVersionUtil.SetActiveRecursive(friendlist[i].gameObject, state: true);
			friendlist[i].isdie = false;
			friendlist[i].Reset_Fri_AI();
		}
	}

	private void Update()
	{
		showFri_hp_dir();
	}

	public List<planefightinfo> GetFightInfo()
	{
		List<planefightinfo> list = new List<planefightinfo>();
		for (int i = 0; i < friendlist.Count; i++)
		{
			if (friendlist[i].fri_type == AI_TYPE.aiplane)
			{
				planefightinfo planefightinfo = new planefightinfo();
				planefightinfo.planeindex = friendlist[i].TypeIndex;
				planefightinfo.selfinfo = friendlist[i].fightinfo;
				list.Add(planefightinfo);
			}
		}
		return list;
	}

	public bool check_list_num(int typeid)
	{
		switch (typeid)
		{
			case 0:
				for (int k = 0; k < friendlist.Count; k++)
				{
					if (!UnityVersionUtil.IsActive(friendlist[k].gameObject))
					{
						return false;
					}
				}
				return true;
			case 1:
				for (int j = 0; j < friendlist.Count; j++)
				{
					if (!UnityVersionUtil.IsActive(friendlist[j].gameObject) && friendlist[j].fri_type == AI_TYPE.aiplane)
					{
						return false;
					}
				}
				return true;
			case 2:
				for (int l = 0; l < friendlist.Count; l++)
				{
					if (!UnityVersionUtil.IsActive(friendlist[l].gameObject) && friendlist[l].fri_type != 0 && friendlist[l].fri_type != AI_TYPE.aiship)
					{
						return false;
					}
				}
				return true;
			case 3:
				for (int i = 0; i < friendlist.Count; i++)
				{
					if (!UnityVersionUtil.IsActive(friendlist[i].gameObject) && friendlist[i].fri_type == AI_TYPE.aiship)
					{
						return false;
					}
				}
				return true;
			default:
				return false;
		}
	}

	public Fri_AIController ship_creat_plane()
	{
		for (int i = 0; i < friendlist.Count; i++)
		{
			if (!UnityVersionUtil.IsActive(friendlist[i].gameObject) && friendlist[i].fri_type == AI_TYPE.aiplane)
			{
				return friendlist[i];
			}
		}
		return null;
	}

	public void check_fightinfo(AI_TYPE dietype, int fri_index, int ai_index)
	{
		infostr = null;
		if (fri_index == -2)
		{
			return;
		}
		if (fri_index == -1)
		{
			plane_smothfollow.instance.change_fightinfo(dietype);
			if (GlobalInf.gamemode == TASKMODE.chanllenge)
			{
				switch (dietype)
				{
					case AI_TYPE.aiplane:
						infostr = "你击败 " + GlobalInf.ai_names[ai_index];
						break;
					case AI_TYPE.aiship:
						infostr = "你摧毁了战舰";
						break;
					case AI_TYPE.aibunker:
						infostr = "你摧毁了塔楼";
						break;
					case AI_TYPE.aihgtw:
						infostr = "你摧毁了塔楼";
						break;
					case AI_TYPE.building:
						infostr = "你摧毁了敌人的基地";
						break;
					case AI_TYPE.smallbuild:
						infostr = "你摧毁了敌人的基地";
						break;
					case AI_TYPE.aiboss:
						infostr = "你摧毁了敌人的基地";
						break;
				}
				UIController.instance.show_fight_info(infostr);
			}
		}
		else
		{
			if (fri_index < 0 || fri_index >= friendlist.Count)
			{
				return;
			}
			friendlist[fri_index].change_fightinfo(dietype);
			if (GlobalInf.gamemode == TASKMODE.chanllenge)
			{
				switch (instance.friendlist[fri_index].fri_type)
				{
					case AI_TYPE.aiplane:
						infostr = GlobalInf.fri_names[fri_index];
						break;
					case AI_TYPE.aiship:
						infostr = "战舰";
						break;
					case AI_TYPE.aibunker:
						infostr = "塔楼";
						break;
					case AI_TYPE.aihgtw:
						infostr = "塔楼";
						break;
				}
				switch (dietype)
				{
					case AI_TYPE.aiplane:
						infostr = infostr + " 击败 " + GlobalInf.ai_names[ai_index];
						break;
					case AI_TYPE.aiship:
						infostr += " 摧毁的战舰";
						break;
					case AI_TYPE.aibunker:
						infostr += " 摧毁的塔楼";
						break;
					case AI_TYPE.aihgtw:
						infostr += " 摧毁的塔楼";
						break;
					case AI_TYPE.building:
						infostr += " 摧毁了敌人的基地";
						break;
					case AI_TYPE.smallbuild:
						infostr += " 摧毁了敌人的基地";
						break;
					case AI_TYPE.aiboss:
						infostr += " 摧毁了敌人的基地";
						break;
				}
				UIController.instance.show_fight_info(infostr);
			}
		}
	}

	public void friplane_reset(Transform player_tra)
	{
		for (int i = 0; i < friendlist.Count; i++)
		{
			if (!UnityVersionUtil.IsActive(friendlist[i].gameObject) && friendlist[i].fri_type == AI_TYPE.aiplane)
			{
				friendlist[i].Reset_Fri_AI();
				tempobj = friendlist[i].gameObject;
				tempobj.transform.forward = player_tra.forward;
				tempobj.transform.position = Cal_Pos_back(player_tra);
				UnityVersionUtil.SetActiveRecursive(friendlist[i].gameObject, state: true);
			}
		}
	}

	public bool CheckFriBoss()
	{
		if (UnityVersionUtil.IsActive(bossobj.gameObject))
		{
			return true;
		}
		return false;
	}

	public void SetAllFalse()
	{
		for (int i = 0; i < friendlist.Count; i++)
		{
			if (UnityVersionUtil.IsActive(friendlist[i].gameObject) && !friendlist[i].isdie && (friendlist[i].fri_type == AI_TYPE.aibunker || friendlist[i].fri_type == AI_TYPE.aihgtw))
			{
				friendlist[i].Setdied();
			}
		}
	}

	public void creat_plane_random(Transform playertr, int num, int attnum)
	{
		Attribute curatt = DataController.instance.DataAttribute[attnum];
		for (int i = 0; i < num; i++)
		{
			tempobj = null;
			backindex = check_ai_type(AI_TYPE.aiplane);
			if (backindex != -1)
			{
				tempobj = friendlist[backindex].gameObject;
				UnityVersionUtil.SetActiveRecursive(tempobj.gameObject, state: true);
			}
			else if (GlobalInf.CurrentQuality > (Quality)101)
			{
				if (UnityEngine.Random.Range(0, 2) > 0)
				{
					FriPlane_num++;
					tempobj = (UnityEngine.Object.Instantiate(Resources.Load("Planes/F22_Fri")) as GameObject);
				}
				else
				{
					FriPlane_num++;
					tempobj = (UnityEngine.Object.Instantiate(Resources.Load("Planes/F2000_Fri")) as GameObject);
				}
			}
			else if (FriPlane_num < LowQuality_limitnum[0])
			{
				FriPlane_num++;
				tempobj = (UnityEngine.Object.Instantiate(Resources.Load("Planes/F22_Fri")) as GameObject);
			}
			if (tempobj == null)
			{
				break;
			}
			tempobj.transform.parent = planeparent;
			tempplane = tempobj.GetComponent<Fri_plane>();
			tempplane.init_plane();
			tempplane.init_info(curatt);
			tempplane.changeHP();
			tempobj.transform.forward = playertr.forward;
			tempobj.transform.position = Cal_Pos_near(playertr);
			if (backindex == -1)
			{
				tempplane.TypeIndex = frilist_index;
				tempplane.minimapindex = minimap_plane_index;
				frilist_index++;
				minimap_plane_index++;
				friendlist.Add(tempplane);
			}
		}
	}

	public Vector3 Cal_Pos_near(Transform bastra)
	{
		if (rightval.Count == 0)
		{
			rightval = new List<int>
			{
				-600,
				-300,
				-10,
				10,
				300,
				600
			};
		}
		if (Vector3.Distance(bastra.position, GlobalInf.centerpoint) > (float)(GlobalInf.flyrange_AI + 1000))
		{
			dirtemp = bastra.forward;
			dirtemp.y = 0f;
			dirtemp = dirtemp.normalized;
			indextemp = UnityEngine.Random.Range(0, rightval.Count);
			valueright = rightval[indextemp];
			rightval.RemoveAt(indextemp);
			return GlobalInf.centerpoint + tempobj.transform.right * valueright + dirtemp * UnityEngine.Random.Range(0, 6) * 50f;
		}
		dirtemp = bastra.forward;
		dirtemp.y = 0f;
		dirtemp = dirtemp.normalized;
		indextemp = UnityEngine.Random.Range(0, rightval.Count);
		valueright = rightval[indextemp];
		rightval.RemoveAt(indextemp);
		return bastra.position + tempobj.transform.right * valueright + dirtemp * UnityEngine.Random.Range(0, 6) * 50f;
	}

	public Vector3 Cal_Pos_back(Transform bastra)
	{
		if (Vector3.Distance(bastra.position, GlobalInf.centerpoint) > (float)(GlobalInf.flyrange_AI + 1000))
		{
			dirtemp = bastra.forward;
			dirtemp.y = 0f;
			dirtemp = dirtemp.normalized;
			return GlobalInf.centerpoint + dirtemp * 3000f + tempobj.transform.right * UnityEngine.Random.Range(-20, 20) * 50f + Vector3.up * (450f + (float)UnityEngine.Random.Range(0, 10) * 20f);
		}
		dirtemp = -bastra.forward;
		dirtemp.y = 0f;
		dirtemp = dirtemp.normalized;
		return bastra.position + dirtemp * 3000f + tempobj.transform.right * UnityEngine.Random.Range(-20, 20) * 50f + Vector3.up * (450f + (float)UnityEngine.Random.Range(0, 10) * 20f);
	}

	public void creat_AI_Fri(NPC_ID_num id_num)
	{
		if (id_num.ID != -1 && id_num.num > 0)
		{
			switch (DataController.instance.DataNPC[id_num.ID].npctype)
			{
				case 0:
					init_friplane(DataController.instance.DataNPC[id_num.ID].npcmode, id_num.num, DataController.instance.DataAttribute[DataController.instance.DataNPC[id_num.ID].attribute_id], id_num.pos_rot);
					break;
				case 1:
					init_friship(DataController.instance.DataNPC[id_num.ID].npcmode, id_num.num, DataController.instance.DataAttribute[DataController.instance.DataNPC[id_num.ID].attribute_id], id_num.pos_rot);
					break;
				case 2:
					init_build(DataController.instance.DataNPC[id_num.ID].npcmode, id_num.num, DataController.instance.DataAttribute[DataController.instance.DataNPC[id_num.ID].attribute_id], id_num.pos_rot);
					break;
			}
		}
	}

	public int check_ai_name(string strname)
	{
		for (int i = 0; i < friendlist.Count; i++)
		{
			if (strname.Equals(friendlist[i].transform.name) && !UnityVersionUtil.IsActive(friendlist[i].gameObject))
			{
				return i;
			}
		}
		return -1;
	}

	public int check_ai_type(AI_TYPE needtype)
	{
		for (int i = 0; i < friendlist.Count; i++)
		{
			if (friendlist[i].fri_type == needtype && !UnityVersionUtil.IsActive(friendlist[i].gameObject))
			{
				return i;
			}
		}
		return -1;
	}

	public void init_friplane(int planetype, int num, Attribute curatt, List<PosRot> posrot)
	{
		for (int i = 0; i < num; i++)
		{
			tempobj = null;
			switch (planetype)
			{
				case 0:
					backindex = check_ai_name("F22_Fri(Clone)");
					if (backindex != -1)
					{
						tempobj = friendlist[backindex].gameObject;
						UnityVersionUtil.SetActiveRecursive(tempobj.gameObject, state: true);
					}
					else if (GlobalInf.CurrentQuality > (Quality)101 || FriPlane_num < LowQuality_limitnum[0])
					{
						FriPlane_num++;
						tempobj = (UnityEngine.Object.Instantiate(Resources.Load("Planes/F22_Fri")) as GameObject);
					}
					break;
				case 1:
					if (GlobalInf.CurrentQuality < (Quality)101)
					{
						backindex = check_ai_name("F22_Fri(Clone)");
						if (backindex != -1)
						{
							tempobj = friendlist[backindex].gameObject;
							UnityVersionUtil.SetActiveRecursive(tempobj.gameObject, state: true);
						}
						else if (FriPlane_num < LowQuality_limitnum[0])
						{
							FriPlane_num++;
							tempobj = (UnityEngine.Object.Instantiate(Resources.Load("Planes/F22_Fri")) as GameObject);
						}
					}
					else
					{
						backindex = check_ai_name("F2000_Fri(Clone)");
						if (backindex != -1)
						{
							tempobj = friendlist[backindex].gameObject;
							UnityVersionUtil.SetActiveRecursive(tempobj.gameObject, state: true);
						}
						else
						{
							FriPlane_num++;
							tempobj = (UnityEngine.Object.Instantiate(Resources.Load("Planes/F2000_Fri")) as GameObject);
						}
					}
					break;
			}
			if (tempobj == null)
			{
				break;
			}
			tempobj.transform.parent = planeparent;
			tempplane = tempobj.GetComponent<Fri_plane>();
			tempplane.init_plane();
			tempplane.init_info(curatt);
			tempplane.changeHP();
			if (posrot == null)
			{
				tempobj.transform.position = new Vector3(UnityEngine.Random.Range(0, 1000), 0f, UnityEngine.Random.Range(2200, 3000));
			}
			else
			{
				tempobj.transform.position = posrot[i].pos;
				tempobj.transform.rotation = Quaternion.Euler(posrot[i].rot);
			}
			if (backindex == -1)
			{
				tempplane.TypeIndex = frilist_index;
				tempplane.minimapindex = minimap_plane_index;
				frilist_index++;
				minimap_plane_index++;
				friendlist.Add(tempplane);
			}
		}
	}

	public void init_friship(int shiptype, int num, Attribute curatt, List<PosRot> posrot)
	{
		for (int i = 0; i < num; i++)
		{
			tempobj = null;
			switch (shiptype)
			{
				case 0:
					backindex = check_ai_name("smallship_Fri(Clone)");
					if (backindex != -1)
					{
						tempobj = friendlist[backindex].gameObject;
						UnityVersionUtil.SetActiveRecursive(tempobj.gameObject, state: true);
					}
					else if (GlobalInf.CurrentQuality > (Quality)101 || FriShip_num < LowQuality_limitnum[1])
					{
						FriShip_num++;
						tempobj = (UnityEngine.Object.Instantiate(Resources.Load("Ships/smallship_Fri")) as GameObject);
					}
					break;
				case 1:
					backindex = check_ai_name("bigship_Fri(Clone)");
					if (backindex != -1)
					{
						tempobj = friendlist[backindex].gameObject;
						UnityVersionUtil.SetActiveRecursive(tempobj.gameObject, state: true);
					}
					else if (GlobalInf.CurrentQuality > (Quality)101 || FriShip_num < LowQuality_limitnum[1])
					{
						FriShip_num++;
						tempobj = (UnityEngine.Object.Instantiate(Resources.Load("Ships/bigship_Fri")) as GameObject);
					}
					break;
				case 2:
					backindex = check_ai_name("mujian_Fri(Clone)");
					if (backindex != -1)
					{
						tempobj = friendlist[backindex].gameObject;
						UnityVersionUtil.SetActiveRecursive(tempobj.gameObject, state: true);
					}
					else if (GlobalInf.CurrentQuality > (Quality)101 || FriShip_num < LowQuality_limitnum[1])
					{
						FriShip_num++;
						tempobj = (UnityEngine.Object.Instantiate(Resources.Load("Ships/mujian_Fri")) as GameObject);
					}
					break;
			}
			if (tempobj == null)
			{
				break;
			}
			tempobj.transform.parent = shipparent;
			tempship = tempobj.GetComponent<Fri_ship>();
			if (backindex == -1)
			{
				tempship.TypeIndex = frilist_index;
				tempship.minimapindex = minimap_ship_index;
				frilist_index++;
				minimap_ship_index++;
				friendlist.Add(tempship);
			}
			tempship.init_ship();
			tempship.init_info(curatt);
			tempship.changeHP();
			if (posrot == null)
			{
				tempobj.transform.position = new Vector3(UnityEngine.Random.Range(0, 1000), 0f, UnityEngine.Random.Range(2200, 3000));
				continue;
			}
			tempobj.transform.position = posrot[i].pos;
			tempobj.transform.rotation = Quaternion.Euler(posrot[i].rot);
		}
	}

	public void init_build(int buildtype, int buildnum, Attribute curatt, List<PosRot> posrot)
	{
		for (int i = 0; i < buildnum; i++)
		{
			tempobj = null;
			switch (buildtype)
			{
				case 0:
					backindex = check_ai_name("hgtw_Fri(Clone)");
					if (backindex != -1)
					{
						tempobj = friendlist[backindex].gameObject;
						UnityVersionUtil.SetActiveRecursive(tempobj.gameObject, state: true);
					}
					else if (GlobalInf.CurrentQuality > (Quality)101 || FriBuild_num < LowQuality_limitnum[2])
					{
						FriBuild_num++;
						tempobj = (UnityEngine.Object.Instantiate(Resources.Load("Building/hgtw_Fri")) as GameObject);
					}
					break;
				case 1:
					backindex = check_ai_name("bunker_Fri(Clone)");
					if (backindex != -1)
					{
						tempobj = friendlist[backindex].gameObject;
						UnityVersionUtil.SetActiveRecursive(tempobj.gameObject, state: true);
					}
					else if (GlobalInf.CurrentQuality > (Quality)101 || FriBuild_num < LowQuality_limitnum[2])
					{
						FriBuild_num++;
						tempobj = (UnityEngine.Object.Instantiate(Resources.Load("Building/bunker_Fri")) as GameObject);
					}
					break;
				case 2:
					backindex = check_ai_name("zhihuibu_Fri(Clone)");
					if (backindex != -1)
					{
						tempobj = friendlist[backindex].gameObject;
						UnityVersionUtil.SetActiveRecursive(tempobj.gameObject, state: true);
					}
					else if (GlobalInf.CurrentQuality > (Quality)101 || FriBuild_num < LowQuality_limitnum[2])
					{
						FriBuild_num++;
						tempobj = (UnityEngine.Object.Instantiate(Resources.Load("Building/zhihuibu_Fri")) as GameObject);
					}
					ishaveboss = true;
					bossobj = tempobj;
					break;
				case 3:
					backindex = check_ai_name("Xinhaota_Fri(Clone)");
					if (backindex != -1)
					{
						tempobj = friendlist[backindex].gameObject;
						UnityVersionUtil.SetActiveRecursive(tempobj.gameObject, state: true);
					}
					else if (GlobalInf.CurrentQuality > (Quality)101 || FriBuild_num < LowQuality_limitnum[2])
					{
						FriBuild_num++;
						tempobj = (UnityEngine.Object.Instantiate(Resources.Load("Building/Xinhaota_Fri")) as GameObject);
					}
					break;
				case 4:
					backindex = check_ai_name("LeiDa_Fri(Clone)");
					if (backindex != -1)
					{
						tempobj = friendlist[backindex].gameObject;
						UnityVersionUtil.SetActiveRecursive(tempobj.gameObject, state: true);
					}
					else if (GlobalInf.CurrentQuality > (Quality)101 || FriBuild_num < LowQuality_limitnum[2])
					{
						FriBuild_num++;
						tempobj = (UnityEngine.Object.Instantiate(Resources.Load("Building/LeiDa_Fri")) as GameObject);
					}
					break;
				case 5:
					backindex = check_ai_name("fangzi1_Fri(Clone)");
					if (backindex != -1)
					{
						tempobj = friendlist[backindex].gameObject;
						UnityVersionUtil.SetActiveRecursive(tempobj.gameObject, state: true);
					}
					else if (GlobalInf.CurrentQuality > (Quality)101 || FriBuild_num < LowQuality_limitnum[2])
					{
						FriBuild_num++;
						tempobj = (UnityEngine.Object.Instantiate(Resources.Load("Building/fangzi1_Fri")) as GameObject);
					}
					break;
				case 6:
					backindex = check_ai_name("fangzi2_Fri(Clone)");
					if (backindex != -1)
					{
						tempobj = friendlist[backindex].gameObject;
						UnityVersionUtil.SetActiveRecursive(tempobj.gameObject, state: true);
					}
					else if (GlobalInf.CurrentQuality > (Quality)101 || FriBuild_num < LowQuality_limitnum[2])
					{
						FriBuild_num++;
						tempobj = (UnityEngine.Object.Instantiate(Resources.Load("Building/fangzi2_Fri")) as GameObject);
					}
					break;
				case 7:
					backindex = check_ai_name("seabuild1_Fri(Clone)");
					if (backindex != -1)
					{
						tempobj = friendlist[backindex].gameObject;
						UnityVersionUtil.SetActiveRecursive(tempobj.gameObject, state: true);
					}
					else if (GlobalInf.CurrentQuality > (Quality)101 || FriBuild_num < LowQuality_limitnum[2])
					{
						FriBuild_num++;
						tempobj = (UnityEngine.Object.Instantiate(Resources.Load("Building/seabuild1_Fri")) as GameObject);
					}
					break;
				case 8:
					backindex = check_ai_name("seabuild2_AI(Clone)");
					if (backindex != -1)
					{
						tempobj = friendlist[backindex].gameObject;
						UnityVersionUtil.SetActiveRecursive(tempobj.gameObject, state: true);
					}
					else if (GlobalInf.CurrentQuality > (Quality)101 || FriBuild_num < LowQuality_limitnum[2])
					{
						FriBuild_num++;
						tempobj = (UnityEngine.Object.Instantiate(Resources.Load("Building/seabuild2_Fri")) as GameObject);
					}
					break;
			}
			if (tempobj == null)
			{
				break;
			}
			tempobj.transform.parent = buildingparent;
			tempbuild = tempobj.GetComponent<Fri_building>();
			if (backindex == -1)
			{
				tempbuild.TypeIndex = frilist_index;
				tempbuild.minimapindex = minimap_build_index;
				frilist_index++;
				minimap_build_index++;
				friendlist.Add(tempbuild);
			}
			tempbuild.init_build();
			tempbuild.init_info(curatt);
			tempbuild.changeHP();
			if (posrot == null)
			{
				tempobj.transform.position = new Vector3(UnityEngine.Random.Range(0, 1000), 0f, UnityEngine.Random.Range(2200, 3000));
				continue;
			}
			tempobj.transform.position = posrot[i].pos;
			tempobj.transform.rotation = Quaternion.Euler(posrot[i].rot);
		}
	}

	public void showFri_hp_dir()
	{
		buildnum = 0;
		for (int i = 0; i < friendlist.Count; i++)
		{
			if (!friendlist[i].isdie)
			{
				friendlist[i].showHPanddir();
				friendlist[i].minimapshow();
				if (friendlist[i].fri_type != AI_TYPE.aiship && friendlist[i].fri_type != 0)
				{
					buildnum++;
				}
			}
			else
			{
				friendlist[i].disappearhp_dir();
				friendlist[i].minimapdis();
			}
		}
		if (GlobalInf.gamemode == TASKMODE.chanllenge && DefendTheBase.instance != null)
		{
			DefendTheBase.instance.CheckbuildNum_fri(buildnum);
		}
	}

	public Fri_AIController calfirhttarget(Vector3 aitrans_pos, bool isplane)
	{
		if (friendlist.Count == 0)
		{
			return null;
		}
		float num = float.PositiveInfinity;
		int index = 0;
		bool flag = false;
		for (int i = 0; i < friendlist.Count; i++)
		{
			if (friendlist[i].isdie)
			{
				continue;
			}
			if (isplane)
			{
				float num2;
				if (friendlist[i].fri_type == AI_TYPE.aiplane)
				{
					num2 = Vector3.Distance(aitrans_pos, friendlist[i].m_transform.position);
					if (num2 < num)
					{
						num = num2;
						index = i;
						flag = true;
					}
					continue;
				}
				num2 = Vector3.Distance(aitrans_pos, friendlist[i].m_transform.position);
				if (num2 < num)
				{
					num = num2;
					index = i;
					flag = true;
				}
				if (UnityEngine.Random.Range(0, 10) > 7)
				{
					num = 0f;
					index = i;
					flag = true;
				}
			}
			else if (friendlist[i].fri_type == AI_TYPE.aiplane)
			{
				float num2 = Vector3.Distance(aitrans_pos, friendlist[i].m_transform.position);
				if (num2 < num)
				{
					num = num2;
					index = i;
					flag = true;
				}
			}
		}
		if (Vector3.Distance(plane_smothfollow.instance.m_Transform.position, aitrans_pos) < num)
		{
			return null;
		}
		if (flag)
		{
			return friendlist[index];
		}
		return null;
	}

	private void OnDestroy()
	{
		if (instance != null)
		{
			instance = null;
		}
	}
}
